using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AutumnEngine.Modules
{
    /// <summary>
    /// Controls the engines logging functions.
    /// </summary>
    public class LoggingModule : Module
    {
        List<string> messages = new List<string>();

        /// <summary>
        /// Writes the specified message.
        /// </summary>
        /// <param name="content">The message.</param>
        /// <param name="level">The level.</param>
        public void Write(string content,LogLevel level)
        {            
            string output = String.Format("[{0}] {1} - {2}", DateTime.Now, levelToString(level), content);
            messages.Add(output);
            if (Engine.Modules.Contains("Engine.Debug"))
            {
                Engine.Modules.Debug.DebugText["Last Log Message"] = output;
            }
        }

        /// <summary>
        /// Updates this instance.
        /// </summary>
        public override void Update()
        {
            foreach (string output in messages)
            {
                #region Console Write
                /*
#if WINDOWS
                Console.WriteLine(output);
#endif
                 */
                #endregion

                Debug.WriteLine(output);

            }
            messages.Clear();
            base.Draw();
        }

        internal string intLevelToString(int level)
        {
            return levelToString((LogLevel)level);
        }

        internal string levelToString(LogLevel level)
        {
            return level.ToString().Replace("LogLevel.","");
        }

       
    }

    /// <summary>
    /// The urgency of the message.
    /// </summary>
    public enum LogLevel
    {
        /// <summary>
        /// Information
        /// </summary>
        Trace = 1,
        /// <summary>
        /// Diagnostics
        /// </summary>
        Debug = 2,
        /// <summary>
        /// Problem
        /// </summary>
        Warning = 3,
        /// <summary>
        /// Error
        /// </summary>
        Error = 4,
        /// <summary>
        /// Big error, cannot recover.
        /// </summary>
        Fatal = 5
    }
}